/*
 * @Copyright: (C) 2019 Zhang Rida. All rights reserved.
 *
 * @Author: Zhang Rida
 * @Email: 215154317@qq.com
 * @FilePath: \WEILA_8910_PROJECT\Third-party\weilasdk\include\wl_message_queue.h
 * @Date: 2021-02-18 15:07:07
 * @Description: message queue for weila osal
 *
 * @LastEditors: Zhang Rida
 * @LastEditTime: 2021-05-12 19:31:50
 */

#ifndef _WL_MESSAGE_QUEUE_H
#define _WL_MESSAGE_QUEUE_H

#include "wl_types.h"

#include "wl_list.h"
#include "wl_ext_os.h"

typedef struct __wl_message_queue WL_MESSAGE_QUEUE;

#define QUEUE_NAME_MAX 40
struct __wl_message_queue {
    wl_char      name[QUEUE_NAME_MAX];
    wl_ext_mutex locked;
    wl_ext_sem   empty;
    wl_list      queue;  //消息
    wl_uint32    limit;  // queue最大数量
};

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * @description: 创建消息队列
 * @param msg_queue 消息队列
 * @param msg_count 最大消息数量
 * @param msg_size 消息大小
 * @return 成功 0 失败 -1
 */
wl_int32 wl_message_queue_create(const wl_char* name,
                                 OUT WL_MESSAGE_QUEUE* msg_queue,
                                 wl_uint32             msg_count,
                                 wl_uint32             msg_size);

/**
 * @description: 发送消息
 * @param msg_queue 消息队列
 * @param msg 消息指针
 * @param msg_size 消息大小
 * @return 成功 0 失败 -1 信号量异常
 */
wl_int32 wl_message_queue_send(WL_MESSAGE_QUEUE* msg_queue, void* msg, wl_size msg_size);

/**
 * @description: 接收消息
 * @param msg_queue 消息队列
 * @param msg 消息指针
 * @param msg_size 消息大小
 * @return 成功 0 失败 -1 信号量异常
 */
wl_int32 wl_message_queue_receive(WL_MESSAGE_QUEUE* msg_queue, void* msg, wl_size msg_size);

/**
 * @description: 删除消息队列
 * @param msg_queue 信号
 * @return 成功 0 失败 -1 信号量异常
 */
wl_int32 wl_message_queue_delete(WL_MESSAGE_QUEUE* msg_queue);

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /*_WL_MESSAGE_QUEUE_H */
